<?php

namespace app\admin\controller;

use think\Db;
use think\Request;


class Examine extends Admin
{


    // 查询数据
    public function index(Request $request)
    {
        $res = $request->get();
        if (!empty($res['title'])) {
            $data = $res['title'];
            $where['title'] = ['like', '%'.$data.'%'];
            $count = Db::table('picture')->where($where)->paginate(5)->count();
            if ($count == 0) {
                 $this->success('未找到查询的内容');
            }
        }else{
            $where = "";
        }
        $data = Db::table('picture')->field(true)->where($where)->paginate(5);
        // var_dump($data);
        // //查询首分类
        // //获取分页显示

        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('data', $data);

        return $this->fetch('examine/index');


    }


    // 通过
    public function pass()
    {
        $id = input('id');
        // var_dump($id);die;

        $status['status'] = 2;

        $res = Db::table('picture')->where('id ='.$id)->update($status);

        // 返回结果
        if ($res > 0) {
           
            $info['status'] = true;
            $info['msg'] = '保存成功';

            return json($info);

        } else {

                      
            $info['status'] = false;
            $info['msg'] = '保存失败';

            return json($info);
        }
    }




    // 不通过
    public function nopass($id)
    {
        $id = input('id');

        $status['status'] = 3;

        $res = Db::table('picture')->where('id ='.$id)->update($status);

        // 返回结果
        if ($res > 0) {
           
            $info['status'] = true;
            $info['msg'] = '保存成功';

            return json($info);

        } else {

                      
            $info['status'] = false;
            $info['msg'] = '保存失败';

            return json($info);
        }
    }


    // 待审核模块
    public function audit(Request $request)
    {
        $res = $request->get();
        
        if (!empty($res['title'])) {
            $data = $res['title'];
            $where['title'] = ['like', '%'.$data.'%'];
            $count = Db::table('picture')->where($where)->paginate(5)->count();
            if ($count == 0) {
                 $this->success('未找到查询的内容');
            }
        }else{
            $where = "";
        }
        $data = Db::table('picture')->field(true)->where($where)->where('status',1)->paginate(5);
        // var_dump($data);
        // //查询首分类
        // //获取分页显示

        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('data', $data);

        return $this->fetch('examine/audit');



    }

    // 审核通过模块
    public function through(Request $request)
    {
        $res = $request->get();
        if (!empty($res['title'])) {
            $data = $res['title'];
            $where['title'] = ['like', '%'.$data.'%'];
            $count = Db::table('picture')->where($where)->paginate(5)->count();
            if ($count == 0) {
                 $this->success('未找到查询的内容');
            }
        }else{
            $where = "";
        }
        $data = Db::table('picture')->field(true)->where($where)->where('status',2)->paginate(5);
        // var_dump($data);
        // //查询首分类
        // //获取分页显示

        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('data', $data);

        return $this->fetch('examine/through');


    }


    //  审核未通过模块
    public function notthrough(Request $request)
    {
        $res = $request->get();
        if (!empty($res['title'])) {
            $data = $res['title'];
            $where['title'] = ['like', '%'.$data.'%'];
            $count = Db::table('picture')->where($where)->paginate(5)->count();
            if ($count == 0) {
                 $this->success('未找到查询的内容');
            }
        }else{
            $where = "";
        }
        $data = Db::table('picture')->field(true)->where($where)->where('status',3)->paginate(5);
        // var_dump($data);
        // //查询首分类
        // //获取分页显示

        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('data', $data);

        return $this->fetch('examine/notthrough');

    }


    
}


